package com.huawei.app.demo.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.huawei.app.demo.MainActivity;
import com.huawei.app.demo.util.LogUtils;

/**
 * 监听HDMI有线投屏插拔事件
 *
 * @since 2021-01-06
 */
public class HDMIEventReceiver extends BroadcastReceiver {

    private static final String TAG = HDMIEventReceiver.class.getSimpleName();
    private MainActivity activity;

    public HDMIEventReceiver(MainActivity activity) {
        this.activity = activity;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if ("com.device.action.HDMI_PLUGIN".equals(action)) {
            LogUtils.getInstance().e(TAG, "HDMI In...");
            Toast.makeText(context, "HDMI In...", Toast.LENGTH_SHORT).show();

            this.activity.showInTopRight();
            this.activity.IS_HDMI_CASTING = true;
        } else if ("com.device.action.HDMI_PLUGOUT".equals(action)) {
            LogUtils.getInstance().e(TAG, "HDMI Out...");
            Toast.makeText(context, "无视频源输入...", Toast.LENGTH_SHORT).show();

            this.activity.resetHDMICastUI();
            this.activity.IS_HDMI_CASTING = false;
        }
    }
}
